<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>Banner图片切换</title>
    <link rel="stylesheet" href="./index.css" />
</head>

<body>
    <div id="mask">
        <div class="center">
            <h2 class="title">天猫双十二惊喜袭来</h2>
            <!-- <img alt="未正确加载图片资源" /> -->
            <img :src="images[currentIndex]" alt="Banner图片" />
            <a href="javascript:void(0)" class="left" @click="prevImage">
                <img src="./images/left.png" alt="上一张" />
            </a>
            <a href="javascript:void(0)" class="right" @click="nextImage">
                <img src="./images/right.png" alt="下一张" />
            </a>
        </div>
    </div>

    <script src="./js/vue.js"></script>
    <script>
        let app = new Vue({
            el: "#mask",
            data: {
                images: [
                    "./images/01.jpg",
                    "./images/02.jpg",
                    "./images/03.jpg",
                    "./images/04.jpg",
                ],
                currentIndex: 0
            },
            methods: {
                prevImage() {
                    this.currentIndex = (this.currentIndex - 1 + this.images.length) % this.images.length;
                },
                nextImage() {
                    this.currentIndex = (this.currentIndex + 1) % this.images.length;
                }
            }
        });
    </script>
</body>

</html>